Details
-
Improvement
-
Resolution: Fixed
-
Major
-
None
-
None
-
None
Description
Please add String charsetEncoding property to SMTPAppenderBase and use it for email's subject and content encoding.
Now javaMail default charset encoding is used so only ASCII latin characters can be used in log messages.
For example my fix for log4j SMTPAppender:
+
private String charsetEncoding = "UTF-8";
public void activateOptions () {
..
addressMessage(msg);
if (getSubject() != null)
/*** Send the contents of the cyclic buffer as an e-mail message. */
@Override
protected void sendBuffer () {
/* Note: this code already owns the monitor for this
appender. This frees us from needing to synchronize on 'cb'. */
try {
final MimeBodyPart part = new MimeBodyPart();
final StringBuilder sb = new StringBuilder();
String t = layout.getHeader();
if (t != null)
final int len = cb.length();
for (int i = 0; i < len; i++) {
final LoggingEvent event = cb.get();
sb.append(layout.format(event));
if (layout.ignoresThrowable()) {
final String[] s = event.getThrowableStrRep();
if (s != null) {
for (int j = 0; j < s.length; j++) { sb.append(s[j]).append(Layout.LINE_SEP); }//for
}//if
}//if
}//for
t = layout.getFooter();
if (t != null) { sb.append(t); }
//fix2:
t = layout.getContentType();
if (t.startsWith("text/"))
else
{ part.setContent(sb.toString(), t); //for non text chartset isn't needed }//if
final Multipart mp = new MimeMultipart();
mp.addBodyPart(part);
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (Exception e)
//try
}//sendBuffer